package com.tm.util;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;

import com.tm.ResultEntity;

/**
 * @author GXL
 */
@Controller
public  class CoreController {

	protected Log logger = LogFactory.getLog(getClass());
	
	/**
	 * 数据校验
	 * @return
	 */
	protected String ddv(HttpServletRequest request, String[] args){
		
		Map params = request.getParameterMap();
		String msg = "";
		
		for(String arg : args){
			if(params.keySet().contains(arg)){
				if(params.get(arg)==null || !StringUtils.hasText(((String[])params.get(arg))[0])){
					msg = "参数【"+arg+"】未明确，请确认！";
					break;
				}
			}else{
				msg = "参数【"+arg+"】未明确，请确认！";
				break;
			}
		}
		
		return msg;
	}
	
	
	/**
	 * 返回结果集
	 * @param errcode
	 * @param errmsg
	 * @param response
	 */
	protected void returnRs(String errcode, String errmsg, HttpServletResponse response){
		ResultEntity re = new ResultEntity(errcode, errmsg);
		
//		ServletUtilsEx.renderJson(response, re);
	}
	
	/**
	 * 返回结果集
	 * @param re
	 * @param response
	 */
	protected void returnRs (ResultEntity re, HttpServletResponse response) {
//		ServletUtilsEx.renderJson(response, re);
	}
	
	
	public Map toResult(int errcode,  String msg, Object data) {
		
		Map res = new HashMap<String, Object>();
		
		res.put("errcode", errcode);
		
		res.put("msg", msg == null ? "" : msg);
		res.put("data", data);
		
		return res;
	}
}
